// https://blog.csdn.net/rxbook/article/details/130654337
package main

import (
	"fmt"
	"os"
)

func main() {
	//自定义一个panic
	println("main start")
	user()
	println("main end")

	/*函数的调用次序为 main -> user -> goods -> info, 在 goods 函数中手动触发 panic,不会再往后执行.
	输出如下:
	main start
	user start
	goods start
	panic: 在 goods 中触发了 panic
	*/
}

func user() {
	println("user start")
	goods()
	println("user end")
}
func goods() {
	defer func() {
		if e := recover(); e != nil {
			fmt.Println("recover the panic:", e)
		}
	}()

	println("goods start")
	//panic(errors.New("在 goods 中触发了 panic"))
	os.Exit(-1)
	info()               //Unreachable code
	println("goods end") //Unreachable code
}
func info() {
	println("info start")
	println("info end")
}
